//
//  TableViewAnimationController.m
//  XKStudyDemo
//
//  Created by xukai on 2017/11/28.
//  Copyright © 2017年 xukai. All rights reserved.
//

#import "TableViewAnimationController.h"
#import "TableViewAnimationKit.h"

@interface TableViewAnimationController ()

@property (nonatomic, assign) NSInteger cellNum;

@end

@implementation TableViewAnimationController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.cellNum = 0;
    [self performSelector:@selector(loadData) withObject:nil afterDelay:0.5];

}

-(void) loadData
{
    self.cellNum = 20;
    [self.tableView reloadData];
    [self starAnimationWithTableView:self.tableView];
    
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithTitle:@"again" style:(UIBarButtonItemStyleDone) target:self action:@selector(againAnimation)];
    self.navigationItem.rightBarButtonItem = rightItem;
    
}

-(void) againAnimation
{
    [self starAnimationWithTableView:self.tableView];
}

- (void)starAnimationWithTableView:(UITableView *)tableView
{
    
    
    switch (self.index) {
        case 0:
        {
            [TableViewAnimationKit leftMoveAnimationWith:tableView];
        }
            break;
        case 1:
        {
             [TableViewAnimationKit downAlphaAnimationWith:tableView];
        }
            break;
        case 2:
        {
             [TableViewAnimationKit downMoveAnimationWith:tableView];
        }
            break;
        case 3:
        {
            [TableViewAnimationKit leftRightMoveAnimationWith:tableView];
        }
            break;
        case 4:
        {
            [TableViewAnimationKit rotateAnimatioWith:tableView];
        }
            break;
        case 5:
        {
            [TableViewAnimationKit upMoveAnimationWith:tableView];
        }
            break;
        case 6:
        {
            [TableViewAnimationKit layDownAnimationWith:tableView];
        }
            break;
            
        case 7:
        {
            [TableViewAnimationKit shrinkToTopAnimationWithTableView:tableView];
        }
            break;
        default:
            break;
    }


    

}

#pragma mark - Table view data source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.cellNum;
}


-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *AnimationID = @"AnimationID";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:AnimationID];
    if(!cell)
    {
        cell = [[UITableViewCell alloc] initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:AnimationID];
        cell.contentView.backgroundColor = [UIColor clearColor];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(20, 10, SCREEN_WIDHT - 40, 100 - 20)];
        view.backgroundColor = [UIColor orangeColor];
        view.layer.masksToBounds = YES;
        view.layer.cornerRadius = 9.0;
        [cell.contentView addSubview:view];
    }
    
    return cell;
}



@end
